package com.ima;
import android.graphics.PorterDuffXfermode;
import android.graphics.Typeface;
import android.graphics.Xfermode;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.dev.ColorTextButton;
import com.dev.GUI;
import com.dev.IconViewClose;
import com.dev.MainActivity;

public class QueryForBlend extends LinearLayout implements OnClickListener{
	WindowManager.LayoutParams wlp=new WindowManager.LayoutParams();
	MainActivity ma;
	LinearLayout titlebar;
	TextView title;
	TextView hint;
	IconViewClose close;
	LinearLayout bts;
	ColorTextButton unuse;
    QueryForBlend(MainActivity ma){
		super(ma);
		this.ma=ma;
		setOrientation(1);
		setBackground(new GUI.BorderDrawable());
		int padding=10;
		int textSize=(int)(13*ma.dp);
		close=new IconViewClose(ma);
		close.setOnClickListener(this);
		title=new TextView(ma);
		title.getPaint().setTextSize(textSize);
		title.setText("色彩混合模式");
		title.setGravity(16);
		title.setPadding(padding,0,0,0);
		titlebar=new LinearLayout(ma);
		titlebar.setOrientation(0);
		titlebar.addView(title,new LayoutParams(0,-1,1f));
		titlebar.addView(close);
		titlebar.setBackground(new GUI.BorderDrawable());
		hint=new TextView(ma);
		hint.setTypeface(Typeface.MONOSPACE);
		hint.setPadding(padding,0,0,0);
		hint.setGravity(16);
		unuse=new ColorTextButton(ma);
		unuse.setText("禁用");
		addView(titlebar,-1,ma.dialogTitleBarHeight);
		addView(hint,-1,ma.dialogTitleBarHeight);
		/*wlp.gravity=Gravity.LEFT|Gravity.TOP;
		wlp.flags=wlp.FLAG_LAYOUT_IN_SCREEN;*/
	}
	ImageManipulationPage imp;
    void show(ImageManipulationPage imp){
		this.imp=imp;
		Xfermode xf=imp.actionPaint.getXfermode();
		if(xf==null){
			hint.setText("未启用");
		}else if(xf instanceof PorterDuffXfermode){
			PorterDuffXfermode pxf=(PorterDuffXfermode)xf;
			hint.setText(pxf.toString());
		}
		wlp.width=ma.wp*4/5;
		wlp.height=-2;
		/*Rect rect=new Rect();
		imp.ivBlend.getGlobalVisibleRect(rect);
		wlp.x=rect.left;
		wlp.y=rect.bottom;*/
		ma.wm.addView(this,wlp);
	}
	void dismiss(){
		ma.wm.removeView(this);
	}
	@Override
	public void onClick(View view) {
		if(view==close){
			dismiss();
		}else if(view==unuse){
			imp.actionPaint.setXfermode(null);
		}
	}
}
